﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;

public partial class Admin_CandidateDetails : System.Web.UI.Page
{
    #region events

    protected void Page_Load(object sender, EventArgs e)
    {
        //CandidateDetailsBO cbo = new CandidateDetailsBO();

        if (!IsPostBack)
        {

            GetStatusRecord();
            //Session["UserID"] = Guid.NewGuid();
        }
    }

    protected void gvSearchResult_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //throw new NotImplementedException();
      
        gvLanguage.PageIndex = e.NewPageIndex;
        //GetGrid();
    }

    #endregion


    #region Methods
    private DataSet GetStatus()
    {

        DataSet objDs=null;
        try
        {
            objDs = new CandidateDetailsBAL().GetStatus();
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog();// throw new ApplicationException(exception.Message);
        }
        return objDs;

    }

    public object InsertDetails(int x, DateTime y)
    {
        CandidateDetailsBO cbo = new CandidateDetailsBO();
        CandidateDetailsBAL cbal = new CandidateDetailsBAL();
        string strReturnValue;
        cbo.StatusID = x;
        cbo.RegApprovedDate = y;
        strReturnValue = (string)cbal.SetStatusIdRegApproveDateForCandidateDetails(cbo.StatusID, cbo.RegApprovedDate);
        return strReturnValue;

    }



    public DataSet GetGrid(int x)
    {
        CandidateDetailsBO cbo = new CandidateDetailsBO();
        DataSet objDs=null;
        try
        {
            cbo.StatusID = x;
            objDs = new CandidateDetailsBAL().DS_GetCandidateDetails(cbo.StatusID);
        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;
    }

    private void GetStatusRecord()
    {

        DataSet objDs = new DataSet();
        statusdropdown.DataSource = GetStatus();
        statusdropdown.DataBind();
        statusdropdown.Items.Insert(0, "--Select--");
        statusdropdown.SelectedIndex = 0;
    }


    #endregion

    protected void gvLanguage_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvLanguage.PageIndex = e.NewPageIndex;
        //GetGrid();


    }

    protected void gvLanguage_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvLanguage.PageIndex = e.NewEditIndex;
        //GetData();
    }

    protected void statusdropdown_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSet objDs = new DataSet();
        int statusid = Convert.ToInt32(statusdropdown.SelectedIndex);
        objDs = GetGrid(statusid);
        gvLanguage.DataSource = objDs;
        gvLanguage.DataBind();
    }
    protected void btnApproved_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in gvLanguage.Rows)
        {
            CheckBox chk = (CheckBox)row.FindControl("ChbGrid");
            if (chk != null && chk.Checked == true && statusdropdown.SelectedValue!="--Select--")
            {
                int index = statusdropdown.SelectedIndex;
                DateTime dtDate = System.DateTime.Now;
                InsertDetails(index, dtDate);
                statusdropdown.SelectedIndex = 0;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Record has been approved successfully.');", true);
                //lblErrorMessage.Text = "Record has been approved successfully.";
                //lblErrorMessage.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Error While Approving The Record.');", true);
                //lblErrorMessage.Text = "Error While Approving The Record.";
                //lblErrorMessage.ForeColor = System.Drawing.Color.Red;
            }
            
        }
    }
}
